package Engine.Module
{
	import flash.utils.getQualifiedClassName;
	
	import library.Function.Dict;

	public class Singleton
	{
		private static var _insDict:Dict = new Dict();
		
		/**
		 * 单实例类,整个游戏只允许存在一个实例.
		 */
		public function Singleton()
		{
			var insName:String = getQualifiedClassName(this);
			if(_insDict.getValue(insName)!= null)
				throw new Error("Error,Can't re instance, please use Singleton.getSingleton()");
			else 
				_insDict.dictionary[insName] = this;
		}
		
		public static function getSingleton(p_class:Class):Singleton
		{
			var insName:String = getQualifiedClassName(p_class);
			var ins:Singleton = _insDict.getValue(insName) as Singleton;
			if(ins == null)
			{
				ins = new p_class() as Singleton;
				
			}
			return ins;
		}
	}
}